using System.Reflection;
using NUnit.Framework;
using ContentRenderingApi;
using ContentRenderingApiSystemTest.Helper;
using System.IO;
using System.Text;

namespace ContentRenderingApiSystemTest.TestFixture
{
    [TestFixture]
    public class RenderStreamTestFixture
    {
        [Test]
        public void ValueCacheOffTest()
        {
            AbstractTemplate template = new EmbeddedResourceTemplate(
                Assembly.GetExecutingAssembly(),
                "ContentRenderingApiSystemTest.TestFixture.Input",
                "Stream");

            template.AddNamedParameter("test", "aaa");

            using(MemoryStream stream = new MemoryStream())
            {
                for(int index = 0; index < 10; index++)
                {
                    template.Render(stream, Encoding.ASCII);
                }

                // reset the position 
                stream.Position =0;

                // convert to a string
                string value = Encoding.UTF8.GetString(stream.ToArray());

                Assert.AreEqual(
                    ResourceHelper.FetchString("ContentRenderingApiSystemTest.TestFixture.Output.Stream.txt"),
                    value);
            }
        }
    }
}
